﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.Core.DomainModel;

namespace MethodWorx.CMS.Content
{
    public class ChildContentCollection : ChildEntityCollection<Page, ContentItem>
    {
        public ChildContentCollection(Page parent, Func<Page, IEnumerable<ContentItem>> loader)
            : base(parent, loader)
        {

        }

        public ContentItem FindByName(string name)
        {
            this.LoadCollection();
            return this.children.FirstOrDefault(c => c.Name.ToLower() == name.ToLower());
        }

        protected override void LoadCollection()
        {
            base.LoadCollection();

            this.children = this.children.OrderBy(c => c.Sequence).ToList();
        }
    }
}
